﻿
namespace HSS.Xaml.UI.Data
{
	#region Using Directives
	using System;
	using System.Collections;
	using System.Windows;
	using System.Windows.Data;
	#endregion

	#region ListCountVisibilityValueConverter
	/// <summary>
	/// Converts a list's count to either <see cref="Visibility.Visible"/> or <see cref="Visibility.Collapsed"/>
	/// </summary>
	public class ListCountVisibilityValueConverter : IValueConverter
	{
		/// <summary>
		/// Converts a list's count to either <see cref="Visibility.Visible"/> or <see cref="Visibility.Collapsed"/>.
		/// </summary>
		/// <param name="value">The value (IList) to convert.</param>
		/// <param name="targetType">Not used.</param>
		/// <param name="parameter">Not used.</param>
		/// <param name="culture">Not used.</param>
		/// <returns><see cref="Visibility.Visible"/> or <see cref="Visibility.Collapsed"/></returns>
		public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
		{
			if (value != null)
			{
				var list = value as IList;
				if (list != null)
				{
					if (null == parameter)
						parameter = "0";
					int minCount = 0;
					if (int.TryParse(parameter.ToString(), out minCount))
						return (list.Count > minCount) ? Visibility.Visible : Visibility.Collapsed;
					return (list.Count > 0) ? Visibility.Visible : Visibility.Collapsed;
				}
			}
			return Visibility.Collapsed;
		}
		/// <summary>
		/// NotImplementedException.
		/// </summary>
		/// <param name="value">Not used.</param>
		/// <param name="targetType">Not used.</param>
		/// <param name="parameter">Not used.</param>
		/// <param name="culture">Not used.</param>
		/// <returns>NotImplementedException.</returns>
		public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
		{
			throw new NotImplementedException();
		}

	}
	#endregion
}